package com.everyday.practice.algorithm;

/**
 * @description: 二叉树的最大深度
 * @author: leon
 * @time: 2021/3/30 16:17
 */
public class Title104 {
    public static void main(String[] args) {
        TreeNode node=new TreeNode();
        node.val=3;
        node.left=new TreeNode(9);
        node.right=new TreeNode(20,new TreeNode(15),new TreeNode(7));
        System.out.println(maxDepth(node));
    }

    public static Integer maxDepth(TreeNode root) {
        return root==null?0:Math.max(maxDepth(root.left),maxDepth(root.right))+1;
    }

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

}
